package com.xncoding.pos.controller.webfluxTest;

import com.xncoding.pos.model.TbUser;
import com.xncoding.pos.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

/**
 * 注解编程模型
 * @Author guoyb
 * @Date 2024/1/30  11:23
 */
@RestController
@RequestMapping("/flux")
public class fluxController {

    private final UserService userService;

    @Autowired
    public fluxController(UserService userService) {
        this.userService = userService;
    }
    //SpringMVC 方式实现，同步阻塞的方式，基于 SpringMVC+Servlet+Tomcat
    // SpringWebflux 方式实现，异步非阻塞 方式，基于 SpringWebflux+Reactor+Netty

    // 根据id查询
    @GetMapping("/{id}")
    public Mono<TbUser> getById(@PathVariable Long id){
        return userService.getById(id);
    }

    // 查询多个
    @GetMapping("/all")
    public Flux<TbUser> getAll(){
        return userService.getAll();
    }

    // 保存
    @PostMapping("/save")
    public Mono<Void> save(@RequestBody Mono<TbUser> userMono){
        return userService.save(userMono);
    }

}
